package org.act.bpel2automata.views.model;

import java.util.ArrayList;
import java.util.LinkedList;

import org.act.BPEL2Automata.automata.SubAutomataImp;
import org.act.BPEL2Automata.automata.module.StatePair;


public class EntityFactory {
	/*
	//TODO FOR TESTING ONLY,REMOVE ME IN THE PRODUCTIVITY.
	public static Object genElements(){
		EntityElement root1 = new EntityElement("Messages");
		EntityElement root2 = new EntityElement("States");
		
		EntityElement level1 = new EntityElement("mes1");
		EntityElement level2 = new EntityElement("mes2");
		EntityElement level3 = new EntityElement("state1");
		
		root1.addChild(level1);
		root1.addChild(level2);
		
		root2.addChild(level3);
		
		{
			ArrayList list = new ArrayList();
			list.add(root1);
			list.add(root2);
			
			return list;
		}
	}
	*/
	
	public static Object genElements(LinkedList<StatePair> sp){
		EntityElement root = new EntityElement("State-Pairs");
		
		for(int i = 0; i < sp.size(); i++){
			root.addChild(new EntityElement("q" + sp.get(i).getStateX().getID() + "&q" + sp.get(i).getStateY().getID(),
					sp.get(i)));
		}
		
		{
			ArrayList list = new ArrayList();
			list.add(root);
			
			return list;
		}
	}
	
	/**
	 * first param <b>automaton1</b> should NOT be null,but <b>automaton2</b> 
	 * can be.
	 * @param automaton1
	 * @param automaton2
	 * @return
	 */
	public static Object genElements(SubAutomataImp automaton1,SubAutomataImp automaton2){
		EntityElement root1 = new EntityElement("Messages");
		EntityElement root2 = new EntityElement("States");
		
		
		for(int i = 0; i < automaton1.getMessageSet().size();i++){
			root1.addChild(new EntityElement("mes" + automaton1.getMessageSet().get(i).getID(),
					automaton1.getMessageSet().get(i)));
		}
		
		for(int i = 0; i < automaton1.getStateSet().size();i++){
			root2.addChild(new EntityElement("q" + automaton1.getStateSet().get(i).getID(),
					automaton1.getStateSet().get(i)));
		}
		
		if(automaton2 != null){
			for(int i = 0; i < automaton2.getStateSet().size();i++){
				root2.addChild(new EntityElement("q" + automaton2.getStateSet().get(i).getID(),
						automaton2.getStateSet().get(i)));
			}
		}
		
		{
			ArrayList list = new ArrayList();
			list.add(root1);
			list.add(root2);
			
			return list;
		}
	}
}
